package com.ruoyi.electricity.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.electricity.domain.TElectricityData;
import com.ruoyi.electricity.service.ITElectricityDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用电Controller
 * 
 * @author ruoyi
 * @date 2023-10-28
 */
@RestController
@RequestMapping("/zdzh/electricityData")
public class TElectricityDataController extends BaseController
{
    @Autowired
    private ITElectricityDataService tElectricityDataService;

    /**
     * 查询用电列表
     */
    //@PreAuthorize("@ss.hasPermi('zdzh:electricityData:list')")
    @GetMapping("/list")
    public TableDataInfo list(TElectricityData tElectricityData)
    {
        startPage();
        List<TElectricityData> list = tElectricityDataService.selectTElectricityDataList(tElectricityData);
        return getDataTable(list);
    }

    /**
     * 导出用电列表
     */
    //@PreAuthorize("@ss.hasPermi('zdzh:electricityData:export')")
    @Log(title = "用电", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TElectricityData tElectricityData)
    {
        List<TElectricityData> list = tElectricityDataService.selectTElectricityDataList(tElectricityData);
        ExcelUtil<TElectricityData> util = new ExcelUtil<TElectricityData>(TElectricityData.class);
        return util.exportExcel(list, "electricityData");
    }

    /**
     * 获取用电详细信息
     */
    //@PreAuthorize("@ss.hasPermi('zdzh:electricityData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(tElectricityDataService.selectTElectricityDataById(id));
    }

    /**
     * 新增用电
     */
    //@PreAuthorize("@ss.hasPermi('zdzh:electricityData:add')")
    @Log(title = "用电", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TElectricityData tElectricityData)
    {
        return toAjax(tElectricityDataService.insertTElectricityData(tElectricityData));
    }

    /**
     * 修改用电
     */
    //@PreAuthorize("@ss.hasPermi('zdzh:electricityData:edit')")
    @Log(title = "用电", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TElectricityData tElectricityData)
    {
        return toAjax(tElectricityDataService.updateTElectricityData(tElectricityData));
    }

    /**
     * 删除用电
     */
    //@PreAuthorize("@ss.hasPermi('zdzh:electricityData:remove')")
    @Log(title = "用电", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tElectricityDataService.deleteTElectricityDataByIds(ids));
    }
}
